/**
 * @file hsv_Detect.cpp
 * @author Anthracene
 * @brief 
 * @version 0.1
 * @date 2018-10-16
 * 
 * @copyright Copyright (c) 2018
 * 
 */
#include "hsv_Detect.h"
#include <iostream>
#include <opencv/cv.hpp>

void detect_HScolor(cv::Mat & img, cv::Mat & dst, int hmin, int hmax, int hmin_, int hmax_, int smin, int smax, int vmin, int vmax)
{
	cv::Mat bgr;
	cv::Mat hsv;
	img.convertTo(bgr, CV_32FC3, 1.0 / 255, 0);
	cvtColor(bgr, hsv, cv::COLOR_BGR2HSV);
	dst = cv::Mat::zeros(img.size(), CV_32FC3);
	cv::Mat mask, mask_;
	inRange(hsv, cv::Scalar(hmin, smin / 255.0, vmin / 255.0), cv::Scalar(hmax, smax / 255.0, vmax / 255.0), mask);
	inRange(hsv, cv::Scalar(hmin_, smin / 255.0, vmin / 255.0), cv::Scalar(hmax_, smax / 255.0, vmax / 255.0), mask_);
	mask = mask + mask_;
	for (int r = 0; r < bgr.rows; r++)
	{
		for (int c = 0; c < bgr.cols; c++)
		{
			if (mask.at<uchar>(r, c) == 255)
			{
				dst.at<cv::Vec3f>(r, c) = bgr.at<cv::Vec3f>(r, c);
			}
		}
	}
	dst.convertTo(dst, CV_8UC3, 255.0, 0);
}
